<?php
include  'incl/Com/ConfigurationSettings.php';
class DbCommon
{
	private $_connected;
	private $_config;
	private $_retResult;
	private $_err;
		
	function ConnectDatabase(){
		$_config=new ConfigurationSettings();
		$dbuser=$_config->getDbUser();
		$dbserver=$_config->getDbServerStr();
		$dbpassword=$_config->getDbPassword();
		$dbname=$_config->getDb();
		
		$_connected=mysql_connect($_config->getDbServerStr(),$_config->getDbUser(),$_config->getDbPassword());

		mysql_select_db($dbname,$_connected) or die('SELECT DATABASE FAILED'.$this->GetLastError(&$_connected));
		
	     return $_connected;
	}
	
	function CloseConnection(&$_connected){
		
		$ret=mysql_close($_connected);
		
		return $ret;
	}
	
	function Query($sqlstatement,&$connectedStatus) {
		$_retResult=mysql_query($sqlstatement,$connectedStatus);
		
		return $_retResult;
	}
	
 function ExecuteQuery($sql){
		$ret;
		
		$_connected=$this->ConnectDatabase();
		
		if(!$_connected){
			die("CONNECT DATABASE FAIL".$this->GetLastError(&$_connected));
		}
		else{
			
			$ret=$this->Query($sql,&$_connected);
			
			if(!$ret){
				die("EXECUTE SQL STATEMENT FAILED".$this->GetLastError(&$_connected));
			}
		}
		
		$this->CloseConnection(&$_connected);
		
		return $ret;
	}
	
	function ExecuteQueryToArray($sql){
		$ret;
		$row;
		
		$_connected=$this->ConnectDatabase();
		if(!$_connected){
			die("".$this->GetLastError(&$_connected))
		}
		else {
			//$ret=$this->Query($sql,&$_connected);
			while ($row = mysql_fetch_array($sql)) {
				$ret=$row;
			}
			
			$this->CloseConnection(&$_connected);
		}
		
		return $ret;
		
	}
	
	function GetLastError(&$_connected){
		$_err=mysql_error($_connected);
		
		return $_err;
	}
	
}
?>